package com.wcqj.taiyi.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;

import com.wcqj.taiyi.Taiyi;

// @RequestMapping("forecast")
@Controller
public class Forecast {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");

    @RequestMapping("/year")
    @ResponseBody
    public String year(@RequestParam(value = "birthDate")String birthDate, @RequestParam(value = "fDate")String fDate) throws ParseException {
        Calendar calBirth=Calendar.getInstance();;
        calBirth.setTime(sdf.parse(birthDate));
        Calendar cal=Calendar.getInstance();
        cal.setTime(sdf.parse(fDate));

        return Taiyi.getYearYao(calBirth, cal);
    }

    @RequestMapping("/month")
    @ResponseBody
    public String month(@RequestParam(value = "birthDate")String birthDate, @RequestParam(value = "fDate")String fDate) throws ParseException {
        Calendar calBirth=Calendar.getInstance();;
        calBirth.setTime(sdf.parse(birthDate));
        Calendar cal=Calendar.getInstance();;
        cal.setTime(sdf.parse(fDate));

        return Taiyi.getMonthYao(calBirth, cal);
    }

    @RequestMapping("/date")
    @ResponseBody
    public String getDateYao(@RequestParam(value = "birthDate")String birthDate, @RequestParam(value = "fDate")String fDate) throws ParseException {
        Calendar calBirth=Calendar.getInstance();;
        calBirth.setTime(sdf.parse(birthDate));
        Calendar cal=Calendar.getInstance();;
        cal.setTime(sdf.parse(fDate));

        return Taiyi.getDateYao(calBirth, cal);
    }
}